<script lang="ts" setup>
import { ref } from 'vue'
import { useMemberStore } from '@/stores'
import { getRecordsListApi } from '@/services/wallet'

const memberStore = useMemberStore()
type recordItem = {
  id: number
  type: number // 类型[1充值,2消费,3储值退款4订单退款]
  money: string
  giftGold: string
  orderSn: string
  createTime: string
}

// 修改获取记录列表的方法，暂时使用模拟数据
const getRecordsList = async (date: string, type: number) => {
  const res = await getRecordsListApi({ date, type })
  if (res.code === 200) {
    listData.value = res.data || []
    console.log(listData.value)
  }
}

let listData = ref<recordItem[]>([])

defineExpose({
  getRecordsList,
})
</script>

<template>
  <view class="center">
    <view class="box" v-if="listData.length > 0">
      <view v-for="item in listData" :key="item.id" class="item">
        <image v-if="item.type === 2" class="icon" src="/static/images/rechargeRecords/xf.png" />
        <image v-if="item.type === 1" class="icon" src="/static/images/rechargeRecords/cz.png" />
        <image v-if="item.type === 3" class="icon" src="/static/images/rechargeRecords/xf.png" />
        <image v-if="item.type === 4" class="icon" src="/static/images/rechargeRecords/cz.png" />
        <view class="item_content">
          <view class="left">
            <view class="title"
              >{{
                item.type === 2
                  ? '消费-'
                  : item.type === 1
                  ? '储值-'
                  : item.type === 3
                  ? '储值-'
                  : '消费-'
              }}{{ item.orderSn }}</view
            >
            <view class="time">{{ item.createTime }}</view>
          </view>
          <view class="right">
            <view
              class="amount"
              :class="{
                positive: item.type === 1 || item.type === 4,
                negative: item.type === 2 || item.type === 3,
              }"
              >{{ item.money }}</view
            >
            <view class="gift"
              >赠送消费金: <text>{{ item.giftGold }}</text></view
            >
          </view>
        </view>
      </view>
    </view>
    <view v-else>
      <view class="noData">
        <image
          src="https://yuefanpai.oss-cn-hangzhou.aliyuncs.com/nolist.png"
          mode="aspectFill"
        />
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.center {
  padding: 0 24rpx;
}

.box {
  width: 100%;
  height: calc(100vh - 186rpx);
  overflow-y: auto;

  .item {
    display: flex;
    align-items: center;
    padding: 36rpx 30rpx;
    background: #fff;
    border-radius: 20rpx;
    margin-bottom: 20rpx;

    .icon {
      width: 52rpx;
      height: 52rpx;
      margin-right: 30rpx;
      flex-shrink: 0;
    }

    .item_content {
      flex: 1;
      display: flex;
      justify-content: space-between;

      .left {
        .title {
          font-size: 30rpx;
          color: #000;
          margin-bottom: 12rpx;
          font-weight: bold;
        }

        .time {
          font-size: 26rpx;
          color: #999;
        }
      }

      .right {
        text-align: right;

        .amount {
          font-size: 32rpx;
          font-weight: 500;
          margin-bottom: 12rpx;

          &.positive {
            color: #4cd964;
          }

          &.negative {
            color: #ff9500;
          }
        }

        .gift {
          font-size: 24rpx;
          color: #999;
        }
      }
    }
  }

  &::-webkit-scrollbar {
    display: none;
  }
}
.noData {
  width: 376rpx;
  height: 334rpx;
  margin: 200rpx auto 0;
  image {
    width: 100%;
    height: 100%;
  }
}
</style>
